<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const arr = [1, 2, 3, [4, 5, 6, ['a', 'b', 'c']]];
      function tree(arr) {
        let r = '<ul>';
        arr.forEach((el, index) => {
          if (Array.isArray(el) === false) {
            r += `<li>${el}</li>`;
          } else {
            r += `<li>i-${index}`;
            r += tree(el);
            // r += '<ul>';
            // el.forEach((ell) => {
            //   r += `<li>${ell}</li>`;
            // });
            // r += '</ul>';
            r += `</li>`;
          }
        });
        r += '</ul>';
        return r;
      }
      // console.log(tree(arr));
      document.write(tree(arr));
    </script>
  </body>
</html>
